﻿using log4net;
using System.IO;
using System;

namespace curbside.Log
{
    /// <summary>
    /// 日志工厂类
    /// </summary>
    /// <author>朱科宇</author>
    /// <mail>zhukeyu@neusoft.com</mail>
    public static class LogFactory
    {
        /// <summary>
        /// 在静态类的静态构造函数中初始化log4net
        /// </summary>
        static LogFactory()
        {
            string filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "config/log4net/log4net.config");
            FileInfo fileInfo = new FileInfo(filePath);
            if (fileInfo.Exists)
            {
                log4net.Config.XmlConfigurator.ConfigureAndWatch(fileInfo);
            }
            else
            {
                log4net.Config.XmlConfigurator.Configure();
            }
        }

        /// <summary>
        /// 提供ILog对象
        /// </summary>
        /// <typeparam name="name">Logger名称</typeparam>
        /// <returns>返回ILog对象</returns>
        public static ILog GetLogger(string name)
        {
            return LogManager.GetLogger(name);
        }
    }
}
